<?php

namespace app\controller;

class AdminRole
{
    public static function read(\app\model\AdminRole $model)
    {
        return $model->read();
    }

    public static function queryRole(\app\model\AdminRole $model)
    {
        return $model->queryRole();
    }

    public function deleteAdminRole(\app\model\AdminRole $model)
    {
        $model->id = input('param.id');
        record_delete_admin_role_operating_log(input('param.id'));
        return boolval($model->deleteAdminRole()) == true ?
            json(200) : json(500);
    }

    public function disable(\app\model\AdminRole $model)
    {
        $model->id = input('param.id');
        $model->disableState = 1;
        record_disable_admin_role_operating_log(input('param.id'));
        return boolval($model->updateDisableState()) == true ?
            json(200) : json(500);
    }

    public function unDisable(\app\model\AdminRole $model)
    {
        $model->id = input('param.id');
        $model->disableState = 0;
        record_un_disable_admin_role_operating_log(input('param.id'));
        return boolval($model->updateDisableState()) == true ?
            json(200) : json(500);
    }

    public function addAdminRole(\app\model\AdminRole $adminRole, \app\model\AdminRoleMenu $adminRoleMenu)
    {
        $adminRole->roleName = input('param.role_name');
        $menuId = implode('|', input('param.menu_id'));
        $roleId = $adminRole->addAdminRole();
        $adminRoleMenu->menuId = $menuId;
        $adminRoleMenu->roleId = $roleId;
        $adminRoleMenu->addAdminRoleMenu();
        record_add_admin_role_operating_log(input('param.role_name'));
        return json(200);
    }

    public function editAdminRole(\app\model\AdminRole $adminRole, \app\model\AdminRoleMenu $adminRoleMenu)
    {
        $adminRole->id = input('param.id');
        $adminRole->roleName = input('param.role_name');
        $menuId = implode('|', input('param.menu_id'));
        $adminRole->editAdminRole();
        $adminRoleMenu->menuId = $menuId;
        $adminRoleMenu->roleId = input('param.id');
        $adminRoleMenu->editAdminRoleMenu();
        record_edit_admin_role_operating_log(input('param.id'));
        return json(200);
    }

    public static function queryData(\app\model\AdminRole $adminRole, int $id)
    {
        $adminRole->id = $id;
        return $adminRole->queryData();
    }
}